package com.cqjtu.eecs.service.impl;

import com.cqjtu.eecs.entity.Student;
import com.cqjtu.eecs.mapper.StudentMapper;
import com.cqjtu.eecs.service.IStudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 学生 服务实现类
 * </p>
 *
 * @author    
 * @since 2022-03-07
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {

    @Resource
    private StudentMapper studentMapper;
    @Override
    public Student selectStudentByStuCode(String stuCode) {
        return studentMapper.selectStudentByStuCode(stuCode);
    }

    @Override
    public List<Student> selectStudentByYearAndMajor(Integer year, String majorCode, Integer currPage, Integer pageSize) {
        return studentMapper.selectStudentByYearAndMajor(year, majorCode, currPage, pageSize);
    }

    @Override
    public List<Student> getAllStudentCount(Integer grade, String majorCode, Integer ncId, Integer currPage, Integer pageSize) {
        return studentMapper.getAllStudentCount(grade, majorCode, ncId, currPage, pageSize);
    }

    @Override
    public Integer getAllStudentCount_sum(Integer grade, String majorCode, Integer ncId) {
        return studentMapper.getAllStudentCount_sum(grade, majorCode, ncId);
    }


    @Override
    public Integer getAllStudentCount2(Integer grade, String majorCode) {
        return studentMapper.getAllStudentCount2(grade, majorCode);
    }

    @Override
    public List<Student> getAllStudentCount2_domain(Integer grade, String majorCode) {
        return studentMapper.getAllStudentCount2_domain(grade,majorCode);
    }

    @Override
    public Map<String, Integer> getCodeIdMap(List<String> codeList) {
        // 将查询出来的map集合转换为map
        Map<String, Integer> codeIdMap = new HashMap<>();
        List<Map<String, Object>> codeIdMapMapList = studentMapper.getCodeIdMap(codeList);
        for (Map<String, Object> map: codeIdMapMapList) {
            String code = null;
            Integer id = null;

            for (Map.Entry<String, Object> entry: map.entrySet()) {
                if ("code".equals(entry.getKey()))
                    code = String.valueOf(entry.getValue());
                if ("id".equals(entry.getKey()))
                    id = (Integer) entry.getValue();
            }
            codeIdMap.put(code, id);
        }
        return codeIdMap;
    }
}
